package com.killuasy.tools.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.killuasy.tools.Symbol;
import com.killuasy.tools.model.UserInfo;

public class Login extends HttpServlet {

	private static final long serialVersionUID = -1268508543970136531L;
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException{
		doPost(request,response);
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		String UserName = request.getParameter("UserName");
		String Password = request.getParameter("Password");
		
		HttpSession session = request.getSession();
		
		if(session!=null&&!session.isNew()){
			
			request.getRequestDispatcher("/index.jsp").forward(request, response);
		}if("killuasy".equals(UserName)&&"killuasy".equals(Password)){
			
			UserInfo userInfo = new UserInfo();	
			session.setAttribute(Symbol.SESSION_KEY_USERINFO, userInfo);
			
			request.getRequestDispatcher("/index.jsp").forward(request, response);
		}else{
			response.sendRedirect("/Killuasy_tools.html");
		}
		
		 
	}
}
